package com.example.androidcomplete0102.ch12;

import com.example.androidcomplete0102.R;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.ImageView;

public class GrideViewEx extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gridviewex);
	
		GridView gridView =(GridView)findViewById(R.id.grid);
		ImageAdapter adapter = new ImageAdapter(); 
		gridView.setAdapter(adapter);
	}
	
	class ImageAdapter extends BaseAdapter{
		
		int[] picture = {R.drawable.ccdam, R.drawable.soyang2,
				R.drawable.dongul, R.drawable.ududong, R.drawable.zipdarigol};
		

		@Override
		public int getCount() {
			return 50;
		}

		@Override
		public Object getItem(int position) {
			return picture[position%5];
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ImageView imgView;
			if(convertView == null){
				imgView = new ImageView(getApplicationContext());
				imgView.setLayoutParams(new GridView.LayoutParams(100,150));
				imgView.setAdjustViewBounds(false);
				imgView.setScaleType(ImageView.ScaleType.CENTER_CROP);
			}else{
				imgView = (ImageView)convertView;
			}
			imgView.setImageResource(picture[position%5]);
			return imgView;
		}
		
	}
}
